﻿var diff;

var status = -1;
var itemList = Array(
    Array(5062000, 1, 200),
    Array(5062002, 1, 300),
    Array(5062009, 1, 400),
    Array(5062001, 1, 400),
    Array(5062010, 1, 600),
    Array(5062500, 1, 600),
    Array(2432306, 1, 1000),
    Array(1190406, 1, 1000),
    Array(2614002, 1, 2000),
    Array(2430692, 1, 2000),
    Array(1112915, 1, 2000),
    Array(1022222, 1, 6000),
    Array(1004075, 1, 10000),
    Array(1032200, 1, 20000),
    Array(1113055, 1, 20000),
    Array(1152154, 1, 20000),
    Array(1003719, 1, 24000),
    Array(1003720, 1, 24000),
    Array(1003721, 1, 24000),
    Array(1003722, 1, 24000),
    Array(3010832, 1, 24000),
    Array(3015002, 1, 40000),
    Array(2432069, 1, 40000)
);
var selectedItem = -1;
var selequantity = -1;
var selectedCost = -1;

function start() {
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == 1) {
        status++;
    } else {
        if (status >= 0) {
            cm.dispose();
            return;
        }
        status--;
    }

    var itemId = 4310248;

    if (status == 0) {
        var selStr = "请选择您要兑换的道具：\r\n请注意，某些道具兑换以后无法交易！#n";
        for (var i = 0; i < itemList.length; i++) {
            selStr += "\r\n#L" + i + "##r" + itemList[i][1] + "#b个 #i" + itemList[i][0] + ":# #b#t" + itemList[i][0] + "#   #r" + itemList[i][2] + "个#bARK纪念币#l";
        }
        cm.sendSimple(selStr);
    } else if (status == 1) {
        var item = itemList[selection];
        if (item != null) {
            selectedItem = item[0];
            selequantity = item[1];
            selectedCost = item[2];
            cm.sendYesNo("您是否购买#i" + selectedItem + ":# #b#t" + selectedItem + "##k x (" + selequantity + ") 需要 #r" + selectedCost + "#k 个ARK纪念币？");
        } else {
            cm.sendOk("出现错误...");
            cm.dispose();
        }
    } else if (status == 2) {
        if (selectedCost <= 0 || selequantity <= 0 || selectedItem <= 0) {
            cm.sendOk("购买道具出现错误...");
            cm.dispose();
            return;
        }
        if (cm.haveItem(itemId, selectedCost)) {
            if (cm.canHold(selectedItem, selequantity)) {
                cm.gainItem(itemId, -selectedCost);
                cm.gainItem(selectedItem, selequantity);
                cm.worldMessage("『钓鱼兑换』 " + cm.getName() + " 玩家使用ARK纪念币兑换了道具： " + cm.getItemName(selectedItem) + " x " + selequantity);
                cm.sendOk("恭喜您成功兑换#i" + selectedItem + ":# #b#t" + selectedItem + "##k x (" + selequantity + ") 。");
            } else {
                cm.sendOk("购买失败，请您确认在背包所有栏目窗口中是否有一格以上的空间。");
            }
        } else {
            cm.sendOk("您没有那么多ARK纪念币。\r\n\r\n购买#i" + selectedItem + ":# #b#t" + selectedItem + "##k x (" + selequantity + ") 需要 #r" + selectedCost + "#k ARK纪念币。");
        }
        status = -1;
    }
}